//
//  XJAllCategoryCell.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/5/7.
//  Copyright © 2018年 Tzyang. All rights reserved.
//  店铺详情---分类--商品分类里面的 cell

#import "XJAllCategoryCell.h"
#import "UIImage+ColorImage.h"

#import "XJAllCategoryModel.h"



@interface XJAllCategoryCell()
/**商品图片*/
@property(nonatomic, strong) UIImageView *ctyGoodIV;
/**商品名*/
@property(nonatomic, strong) UILabel *ctyGoodTitleLb;
/**价格*/
@property(nonatomic, strong) UILabel *ctyGoodPriceLb;
/**弃用价格 高价*/
@property(nonatomic, strong) UILabel *ctyGoodDiscardLb;
@end

@implementation XJAllCategoryCell
#pragma mark - lazy
- (UIImageView *)ctyGoodIV {
    if (!_ctyGoodIV) {
        _ctyGoodIV = [UIImageView new];
        [self addSubview:_ctyGoodIV];
    }
    return _ctyGoodIV;
}

- (UILabel *)ctyGoodTitleLb {
    if (!_ctyGoodTitleLb) {
        UILabel *ctyTitleLb = [UILabel new];
        self.ctyGoodTitleLb = ctyTitleLb;
        [self addSubview:ctyTitleLb];
    }
    return _ctyGoodTitleLb;
}

- (UILabel *)ctyGoodPriceLb {
    if (!_ctyGoodPriceLb) {
        _ctyGoodPriceLb = [UILabel new];
        [self addSubview:_ctyGoodPriceLb];
    }
    return _ctyGoodPriceLb;
}

- (UILabel *)ctyGoodDiscardLb {
    if (!_ctyGoodDiscardLb) {
        _ctyGoodDiscardLb = [UILabel new];
        [self addSubview:_ctyGoodDiscardLb];
    }
    return _ctyGoodDiscardLb;
}

#pragma mark - 初始化方法
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self createSubView];
    }
    return self;
}

#pragma mark - 创建子视图
- (void)createSubView {
    // iv
    self.ctyGoodIV.frame = CGRectMake(ADAPTWidth(4), 0, (KWidth-4)/2, (KWidth-4)/2);
    UIImage *placeholderImg = [UIImage imageWithColor:XJCOLOR_RGB(211, 211, 211)];
    [self.ctyGoodIV sd_setImageWithURL:[NSURL URLWithString:@"http://static.zertone1.com/q1kqeZ8AmaraNBKHnJNwwPHwVXqiPFQd.png"] placeholderImage:placeholderImg];
    self.ctyGoodIV.contentMode = UIViewContentModeScaleAspectFit;
    self.ctyGoodIV.layer.masksToBounds = YES;
    self.ctyGoodIV.layer.cornerRadius = 10.0;
    self.ctyGoodIV.sd_layout.centerXEqualToView(self).topEqualToView(self).widthIs(ADAPTWidth(175)).heightIs(ADAPTHeight(175));
    
    // 商品名
    NSString *titleStr = @"洁柔手帕纸洁柔手帕纸洁柔手帕纸洁柔手帕纸洁柔手帕纸";
    self.ctyGoodTitleLb.font = XJFONTSET_R(14);
    self.ctyGoodTitleLb.textColor = XJCOLOR_RGB(17, 17, 17);
    self.ctyGoodTitleLb.text = titleStr;
    self.ctyGoodTitleLb.numberOfLines = 2;
    
    self.ctyGoodTitleLb.sd_layout.leftSpaceToView(self, ADAPTHeight(8)).topSpaceToView(self.ctyGoodIV, 4).widthIs(ADAPTHeight(175)).heightIs(50);
    
    
    // 价格
    self.ctyGoodPriceLb.font = XJFONTSET_M(16);
    self.ctyGoodPriceLb.textColor = XJCOLOR_RGB(244, 67, 54);
    NSString * priceLb_title = @"¥99.00";
    self.ctyGoodPriceLb.text = priceLb_title;
    UIFont * priceLb_font = self.ctyGoodPriceLb.font;
    
    CGFloat priceLb_w = [UILabel labelWithLabel:self.ctyGoodPriceLb getWidthWithTitle:priceLb_title font:priceLb_font];
    CGFloat priceLb_h = [UILabel labelWithLabel:self.ctyGoodPriceLb getHeightByWidth:priceLb_w title:priceLb_title font:priceLb_font];
    
    self.ctyGoodPriceLb.sd_layout.leftSpaceToView(self, ADAPTHeight(8)).topSpaceToView(self.ctyGoodTitleLb, 1.5).widthIs(priceLb_w*1.5).heightIs(priceLb_h);
    
    
    // 原价 高价
    self.ctyGoodDiscardLb.font = XJFONTSET_M(14);
    self.ctyGoodDiscardLb.textColor = XJCOLOR_RGB(121, 130, 133);
    NSString *discardStr = @"¥199.00";
    UIFont *discardFont = self.ctyGoodDiscardLb.font;
    
    CGFloat discardLb_w = [UILabel labelWithLabel:self.ctyGoodDiscardLb getWidthWithTitle:discardStr font:discardFont];
    CGFloat discardLb_h = [UILabel labelWithLabel:self.ctyGoodDiscardLb getHeightByWidth:discardLb_w title:discardStr font:discardFont];
    
    self.ctyGoodDiscardLb.sd_layout.rightSpaceToView(self, ADAPTHeight(8)).topSpaceToView(self.ctyGoodTitleLb, 2).widthIs(discardLb_w).heightIs(discardLb_h);
    
    //添加中划线
    NSDictionary *attDic = @{NSStrikethroughStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleSingle]};
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:discardStr attributes:attDic];
    self.ctyGoodDiscardLb.attributedText = attStr;
}



- (void)setModel:(XJAllCategoryModel *)model {
    _model = model;
    
    UIImage *placeholdeImg = [UIImage imageNamed:@"default_goods"];
    
    [self.ctyGoodIV sd_setImageWithURL:[NSURL URLWithString:model.cover] placeholderImage:placeholdeImg];
    
    self.ctyGoodTitleLb.text = model.name;
    
    
    self.ctyGoodPriceLb.text = [NSString stringWithFormat:@"￥%.2f",[model.price floatValue]];
    
    NSString *marketPrice = [NSString stringWithFormat:@"%.2f",[model.market_price floatValue]];
    
    NSDictionary *dic = @{NSStrikethroughStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleSingle]};
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:marketPrice attributes:dic];
    
    self.ctyGoodDiscardLb.attributedText = attStr;
}



@end
